<template>
    <div class="goods">
        <van-nav-bar title="商品详情" left-arrow @click-left="backUp"/>
        <van-swipe class="goods-swipe" :autoplay="3000">
            <van-swipe-item v-for="(item,index) in images" :key="index">
                <img v-lazy="item"/>
            </van-swipe-item>
        </van-swipe>

        <van-cell-group>
            <van-cell>
                <div class="goods-title">{{ commodityDto.goodsName }}</div>
                <div class="goods-price">
                    <van-tag type="danger" style="margin: 0 5px;">补货</van-tag>
                    &yen;{{ commodityDto.price }}
                </div>
            </van-cell>
        </van-cell-group>

        <van-tabs v-model="active" animated color="#FBA86F">
            <van-tab title="商品介绍">
                <div class="html" v-html="commodityDto.introduction"></div>
            </van-tab>
        </van-tabs>

        <van-goods-action class="goods-action">
            <van-goods-action-big-btn primary @click="toBuy()">立即补货</van-goods-action-big-btn>
        </van-goods-action>
    </div>
</template>

<script>
    import {
        Tag,
        Col,
        Icon,
        Cell,
        CellGroup,
        Swipe,
        Toast,
        Skeleton,
        SwipeItem,
        GoodsAction,
        GoodsActionBigBtn,
        GoodsActionMiniBtn,
        Popup,
        Stepper,
        Tabs,
        Tab
    } from "vant";
    import api from "../../utils/restful";

    export default {
        components: {
            [Tag.name]: Tag,
            [Col.name]: Col,
            [Icon.name]: Icon,
            [Cell.name]: Cell,
            [CellGroup.name]: CellGroup,
            [Swipe.name]: Swipe,
            [SwipeItem.name]: SwipeItem,
            [GoodsAction.name]: GoodsAction,
            [GoodsActionBigBtn.name]: GoodsActionBigBtn,
            [GoodsActionMiniBtn.name]: GoodsActionMiniBtn,
            [Popup.name]: Popup,
            [Stepper.name]: Stepper,
            [Tabs.name]: Tabs,
            [Tab.name]: Tab
        },
        data() {
            return {
                commodityDto: {}, // 商品信息
                images: [],
                showSku: false,
                current: 0,
                buy_type: "",
                num: 1,
                active: 0 //切换商品详情和用户评价
            };
        },
        mounted() {
            this.getGoodsDetail();
        },
        methods: {
            // 商品详情
            getGoodsDetail() {
                this.$axios({
                    method: "get",
                    url: api.replenishDetail,
                    params: {
                        token: localStorage.getItem("token"),
                        goodsId: this.$route.query.goods_id
                    }
                }).then(res => {
                    console.log(res);
                    this.commodityDto = res.data;
                    this.images = res.data.images.split(",");
                });
            },
            toBuy() {
                this.$router.push({
                    name: "replenishconfirm",
                    query: {
                        goods_id: this.commodityDto.goodsId
                    }
                });
            },
            backUp() {
                this.$router.go(-1);
            }
        }
    };
</script>

<style lang="less" scoped>
    @import "~style/common.less";

    .goods {
        padding-bottom: 50px;

        &-swipe {
            img {
                width: 100%;
                display: block;
            }
        }

        &-title {
            font-size: 16px;
        }

        &-price {
            color: #f44;
        }

        &-express {
            color: #999;
            font-size: 12px;
            padding: 5px 15px;
        }

        &-cell-group {
            // margin: 10px 0;
            .van-cell__value {
                color: #999;
            }
        }

        &-tag {
            margin-left: 5px;
        }

        &-action {
            z-index: 99;
        }

        .comment {
            background-color: #fff;
            font-size: 14px;

            li {
                padding: 10px 15px;
                border-bottom: 1px solid #eee;
            }

            .avatar {
                width: 35px;
                height: 35px;
                border-radius: 50%;
                margin-right: 10px;
            }

            .time {
                font-size: 12px;
                float: right;
                margin-top: 8px;
            }

            p {
                padding: 10px;
            }

            .img {
                border-radius: 10px;
                width: 32%;
                height: 120px;
                margin-right: 1%;
            }
        }

        .no-comment {
            font-size: 14px;
            padding: 10px 15px;
            background-color: #fff;
        }

        .sku {
            padding: 20px 10px;
            font-size: 14px;
            color: #333;

            .sku-top {
                display: flex;
                align-items: center;

                img {
                    width: 150px;
                    height: 120px;
                }

                .sku-text {
                    padding-left: 10px;
                    display: flex;
                    flex-direction: column;
                    font-size: 15px;

                    .name {
                        color: #030303;
                    }

                    .price {
                        color: @priColor;
                    }

                    .inventory {
                        color: #666;
                    }
                }
            }

            .sku-list {
                padding: 10px 0;
                display: flex;
                flex-wrap: wrap;

                li {
                    margin: 8px 2%;
                    flex-basis: 45%;
                    line-height: 30px;
                    text-align: center;
                    border-radius: 20px;
                    font-size: 15px;
                    border: 1px solid #333;
                }

                li.active {
                    color: #fff;
                    border: 1px solid @priColor;
                    background-color: @priColor;
                }
            }

            .stepper {
                margin: 10px 0;
                display: flex;
                justify-content: space-between;
                align-items: center;
            }

            button {
                width: 100%;
                height: 40px;
                line-height: 40px;
                text-align: center;
                border-radius: 20px;
                color: #fff;
                font-size: 15px;
                background-color: @priColor;
                border: 0px;
                outline: none;
            }
        }
    }
</style>

<style lang="less">
    .html {
        width: 100%;

        p {
            width: 100%;
        }

        img {
            display: block;
            width: 100% !important;
        }
    }
</style>